Add reshape support for DiffCache resizing#180
Conversation
f412824 to
ead730d
Compare
|
Follow-up for the PreallocationTools test coverage request. Added core resizing tests for:
The Local validation run on commit
|
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
81f6362 to
8e9dc89
Compare
|
Added QA AllocCheck coverage for the reshaped DiffCache paths. New QA pieces:
I intentionally did not put the ForwardDiff dual Rebased onto current Local validation on rebased commit
|
Draft PR. Please ignore until reviewed by @ChrisRackauckas.
Summary
reshape(::DiffCache, dims...)so vector-backedDiffCachestorage can be presented as a multidimensional cache without callers reaching into.du/.dual_du.resize!d and reshaped again.DiffCaches.ArrayInterface.restructure.1.3.0for the new public API.Root Cause
The issue workflow needed multidimensional
DiffCacheaccess while keeping resizeable vector storage. A plainreshape(vector, dims...)marks the vector as shared and prevents laterresize!, while the existing public API did not expose the field/unsafe_wrappattern safely.The initial implementation used a view-backed reshape for safety, but the ForwardDiff path for that wrapper fell back to
ArrayInterface.restructure, which copied into a fresh matrix. The current implementation adds a vector-backed reshaped-cache fast path soget_tmpremains zero-copy and writes alias the raw dual storage, without relying on non-publicBase.ReshapedArrayin source.Fixes #140.
Performance Notes
Benchmarked locally with BenchmarkTools after rebasing onto current
master, on a 1000-element vector-backed cache reshaped to(20, 50):get_tmpfor reshaped dual cache:23.63 ns,0 bytesget_tmp:23.63 ns,0 bytesreshape(DiffCache vector):5.63 ns,0 bytesunsafe_wrap(Array, pointer, dims):45.35 ns,48 bytesunsafe_wrapand ordinary matrix timings and allocated0 bytesStridedArrays and the dual temporary aliasesdual_duNon-standard probes:
SubArrayandLVectorvector-backed reshapes return strided, zero-copy reshaped dual temporaries.LArraymatrix reshapes stay on the existingArrayInterface.restructurefallback, preserving wrapper behavior instead of applying the vector-backed fast path.VectorOfArrayreshaped normal access remains zero-allocation.Validation
timeout 3600 /home/crackauc/.juliaup/bin/julia +1.10 --project=. test/core_resizing.jltimeout 3600 /home/crackauc/.juliaup/bin/julia +1.10 --project=. -e 'using Runic; Runic.main(ARGS)' -- --check --diff .timeout 3600 /home/crackauc/.juliaup/bin/julia +1.10 --project=. -e 'using Pkg; Pkg.test()'GROUP=QA timeout 3600 /home/crackauc/.juliaup/bin/julia +1 --project=. -e 'using Pkg; Pkg.test()'429during Documenterlinkcheck; retrying the same command unchanged passed:timeout 3600 /home/crackauc/.juliaup/bin/julia +1.10 --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate(); include("docs/make.jl")'perf_env, removed after use.